package com.wandian.texas.entity;

import com.wandian.util.Log;

/**
 * @author long
 * @Create 2012-10-8 上午11:40:13
 * @QQ 108232706
 * @version 1.0
 * @description DataObject
 */
public class DataObject {

	private short op = 0;

	public final void setOp(short option) {
		if ((this.op == 1) && (option == 2)) {
			return;
		}
		this.op = option;
	}

	public final void beforeAdd() {
		this.op = 1;
	}

	public final void resetUpdate() {
		this.op = 2;
	}

	public final short getOp() {
		return this.op;
	}

	public boolean beginAdd() {
		if (getOp() == 1) {
			setOp((short) 0);
			return true;
		}
		return false;
	}

	public void commitAdd(boolean result) {
		if (!result) {
			setOp((short) 1);
			Log.error("添加出错了，状态还原" + toString());
		}
	}

	public boolean beginUpdate()
	{
		if (getOp() == 2) {
			setOp((short) 0);
			return true;
		}
		return false;
	}

	public void commitUpdate(boolean result) {
		if (!result) {
			setOp((short) 2);
			Log.error("更新出错了，状态还原>>>" + toString());
		}
	}
}